<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head th:fragment="head(title)">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:text="${title} + ' - 校园二手书交易平台'">页面标题</title>
    
    <!-- Favicon -->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    
    <!-- CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/static/css/style.css}">
    
    <!-- Page Loader -->
    <style th:inline="css">
        /* Critical CSS for first render */
        #page-loader {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background-color: rgba(255, 255, 255, 0.9);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 9999;
            transition: opacity 0.5s ease;
        }
    </style>
</head>
<body>
    <!-- Page Loader -->
    <div id="page-loader">
        <div class="loader-spinner"></div>
    </div>
    
    <!-- Navigation Bar Fragment -->
    <nav th:fragment="navbar(active)" class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" th:href="@{/}">
                <i class="fas fa-book-reader mr-2"></i>校园二手书交易
            </a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item" th:classappend="${active == 'home'} ? 'active' : ''">
                        <a class="nav-link" th:href="@{/}">
                            <i class="fas fa-home mr-1"></i>首页
                        </a>
                    </li>
                    <li class="nav-item" th:classappend="${active == 'books'} ? 'active' : ''">
                        <a class="nav-link" th:href="@{/book/list}">
                            <i class="fas fa-book mr-1"></i>书籍列表
                        </a>
                    </li>
                    <li class="nav-item" th:classappend="${active == 'publish'} ? 'active' : ''">
                        <a class="nav-link" th:href="@{/book/publish}">
                            <i class="fas fa-plus-circle mr-1"></i>发布书籍
                        </a>
                    </li>
                </ul>
                
                <!-- 用户菜单 -->
                <ul class="navbar-nav" sec:authorize="isAuthenticated()">
                    <li class="nav-item" th:classappend="${active == 'my-books'} ? 'active' : ''">
                        <a class="nav-link" th:href="@{/book/my-books}">
                            <i class="fas fa-book-open mr-1"></i>我的书籍
                        </a>
                    </li>
                    <li class="nav-item" th:classappend="${active == 'my-orders'} ? 'active' : ''">
                        <a class="nav-link" th:href="@{/order/my-orders}">
                            <i class="fas fa-shopping-cart mr-1"></i>我的订单
                        </a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" 
                           data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <i class="fas fa-user mr-1"></i>
                            <span sec:authentication="name">用户名</span>
                        </a>
                        <div class="dropdown-menu dropdown-menu-right">
                            <a class="dropdown-item" th:href="@{/user/profile}">
                                <i class="fas fa-id-card mr-2"></i>个人资料
                            </a>
                            <div class="dropdown-divider"></div>
                            <form th:action="@{/logout}" method="post" class="dropdown-item">
                                <button type="submit" class="btn btn-link text-danger p-0">
                                    <i class="fas fa-sign-out-alt mr-2"></i>退出登录
                                </button>
                            </form>
                        </div>
                    </li>
                </ul>
                
                <!-- 未登录菜单 -->
                <ul class="navbar-nav" sec:authorize="!isAuthenticated()">
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/login}">
                            <i class="fas fa-sign-in-alt mr-1"></i>登录
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/register}">
                            <i class="fas fa-user-plus mr-1"></i>注册
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    
    <!-- Breadcrumb Fragment -->
    <div th:fragment="breadcrumb(breadcrumbs)" class="container">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a th:href="@{/}">
                        <i class="fas fa-home"></i>
                    </a>
                </li>
                <li th:each="crumb : ${breadcrumbs}" 
                    th:class="'breadcrumb-item' + (${crumb.url == ''} ? ' active' : '')">
                    <a th:if="${crumb.url != ''}" th:href="@{${crumb.url}}" th:text="${crumb.title}">链接</a>
                    <span th:if="${crumb.url == ''}" th:text="${crumb.title}">当前页</span>
                </li>
            </ol>
        </nav>
    </div>
</body>
</html> 